﻿
//import com.porganized.heatmap.hBitmapData;


var myBitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
//var myBitmapData:hBitmapData = new hBitmapData(40, 80, false, 0x000000);
var red:uint = 0xFF0000;

var pixelValue:uint = myBitmapData.getPixel(50, 50);
trace(pixelValue.toString(16));

function diffColors (startColor, endColor, currentColor, increments, currentIncrement) {
					var rDifference = (endColor >> 16 & 0xFF) - (startColor >> 16 & 0xFF); 
					var gDifference = (endColor >> 8 & 0xFF) - (startColor >> 8 & 0xFF);
					var bDifference = (endColor & 0xFF) - (startColor & 0xFF);
					
					var rIncrement = Math.round(rDifference / increments);
					var gIncrement = Math.round(gDifference / increments);
					var bIncrement = Math.round(bDifference / increments);
					
					var currentR = (startColor >> 16 & 0xFF)+(currentIncrement * rIncrement);
					var currentG = (startColor >> 8 & 0xFF)+(currentIncrement * gIncrement);
					var currentB = (startColor & 0xFF)+(currentIncrement * bIncrement);
					
					return ("0x" + d2h(currentR) + d2h(currentG) + d2h(currentB))
				}

function pixelAt (percent) {
 var numpixels:uint = myBitmapData.width*myBitmapData.height;
 var currentPix = numpixels*percent/100;
 var currentPixRow = Math.floor(currentPix/myBitmapData.width);
 var currentPixColumn = currentPix-currentPixRow*myBitmapData.width;
 
	trace (numpixels, currentPix, currentPixRow, currentPixColumn);
	
	for (var i = 0; i < 10; i++) {
		if (i == 0) myBitmapData.setPixel(currentPixColumn, currentPixRow, 0xFF0000);
		else {
			for (var j = 0; j <= i; j++ ) {
				myBitmapData.setPixel(currentPixColumn+j, currentPixRow+(i-j), diffColors (0xFF0000, 0x000000, 0xFF0000, 10+2, i+1));
				myBitmapData.setPixel(currentPixColumn-j, currentPixRow+(i-j), diffColors (0xFF0000, 0x000000,0xFF0000, 10+2, i+1));
				myBitmapData.setPixel(currentPixColumn+(i-j), currentPixRow-j, diffColors (0xFF0000, 0x000000,0xFF0000, 10+2, i+1));
				myBitmapData.setPixel(currentPixColumn-(i-j), currentPixRow - j, diffColors (0xFF0000, 0x000000, 0xFF0000, 10 + 2, i + 1));
			}
		}
		
	}
	

}

function d2h( d:int ) : String { //decimal to hex, as found at: http://goflashgo.wordpress.com/2007/03/28/simple-actionscript-hex2decdec2hex-methods/
	var c:Array = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ];
	if( d > 255 ) d = 255;
	var l:int = d / 16;
	var r:int = d % 16;
	return c[l]+c[r];
}

for (var i:uint = 0; i < 6; i++)
{
//pixelAt (i * (100 / 6));
}
pixelAt (45);
pixelAt (90);
pixelAt (10);

var myBitmapImage:Bitmap = new Bitmap(myBitmapData);
addChild(myBitmapImage);
myBitmapImage.width = 200;
myBitmapImage.height = 400;
